define(['jquery','lodash','lodash_fp','app/utils', 'maybe'], ($,_,fp,U,M) => {

  (async function start() {
    M.map(render_shops,await get_shops())
  }())


  //render_shops : List Shop -> ()
  function render_shops(shops) {
    _.map(shops,s => {
      $('#shop_list').append(`<a class="collection-item" href="/pages/user-end/shop.html?id=${s.id}">${s.name}</a>`)
    })
  }


  //get_shops : Maybe (List Shop)
  function get_shops() {
    return new Promise((resolve, reject) => {
      $.get('/user-end/shops').then(res => {
        console.log(res)
        if(U.is_res_ok(res)){
          resolve(M.just(U.result(res)))
        }else{
          alert('获取商店列表失败' + (U.is_empty_string(U.error(res)) ? '' : (': ' + U.error(res))))
          resolve(M.nothing())
        }
      })
    })
  }

})